using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;

using ZoneFiveSoftware.Common.Data;
using ZoneFiveSoftware.Common.Data.Fitness;
using ZoneFiveSoftware.Common.Data.GPS;
using ZoneFiveSoftware.Common.Visuals;
using ZoneFiveSoftware.Common.Visuals.Fitness;

using BENBUN.Properties;
using BENBUN.UI.Forms;
using BENBUN.Utils;


namespace BENBUN.WIW
{
    partial class ExportActivityToWIW : IAction
    {
        public ExportActivityToWIW(IList<IActivity> activities)
        {
            this.activities = activities;
        }

        #region IAction Members

        public bool Enabled
        {
            get
            {

                if (activities == null || activities.Count == 0) return false;

                bool valid = false;

                for (int i = 0; i < activities.Count; i++)
                {
                    if (activities[i].GPSRoute != null)
                    {
                        if (activities[i].GPSRoute.Count > 0 && activities[i].StartTime < DateTime.Now)
                        {
                            valid = true;
                        }
                    }
                }

                return valid;
            }
        }

        public bool HasMenuArrow
        {
            get { return false; }
        }

        public Image Image
        {
            get { return Properties.Resources.Image_16_Export; }
        }

        public void Refresh()
        {
        }

        public void Run(Rectangle rectButton)
        {
            if (Controller.GetInstance().SessionToken == null)
            {
                //MessageBox.Show("nooq!");
                ExportWarning warningForm = new ExportWarning();
                warningForm.ShowDialog();
               // IApplication application = Plugin.GetApplication();
               // application.ShowView(GUIDStore.SettingsView, "PageId=" + GUIDStore.TestView.ToString());
            }

            else
            {
                if (activities.Count == 1)
                {
                    Controller.GetInstance().Export(activities[0], true);
                }
                else
                {
                    LoadMultipleConfirmation form = new LoadMultipleConfirmation();
                    form.activities = activities;
                    form.ShowDialog();
                }
            }
        }

        public string Title
        {
            get
            {
                if (this.activities.Count == 1)
                {
                    return String.Format(Resources.PluginExportAction, string.Empty);
                }
                else
                {
                    return String.Format(Resources.PluginExportActionMultiple, this.activities.Count);
                }
            }
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private IActivity activity = null;
        private IList<IActivity> activities;

    }
}
